package com.example.javatwo.controller.cg.wmj;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.javatwo.pojo.cg.wmj.PurchaseReturn;
import com.example.javatwo.pojo.cg.wmj.Supplier;
import com.example.javatwo.pojo.cg.wmj.SupplierType;
import com.example.javatwo.pojo.xs.zqy.PageBean;
import com.example.javatwo.service.cg.wmj.SupplierService;
import com.example.javatwo.service.cg.wmj.buyReturnService;


@Controller
public class Conter {
	@RequestMapping("/we")
	public String ss() throws Exception{
		return "/cg/wmj/cgth";
	}
	
	@RequestMapping("/wee")
	public String sss() throws Exception{
		return "/cg/wmj/gongyingsang";
	}
	@Autowired
	private buyReturnService ser;
	
	
	//主祥查询
	@RequestMapping("/queryBuy")
	@ResponseBody
//	public PageBean findYszhu(int currentPage){
//		Integer count = this.ysservice.findzong();
//		Object pageobj = this.ysservice.findYszhu(currentPage);
//		PageBean bean = new PageBean(count,currentPage, pageobj);
//		return bean;
//	}
	public PageBean wq(int currentPage) throws Exception{
		Integer count = this.ser.QuerySumCount();
		Object pageobj = this.ser.QueryBuy(currentPage);
		PageBean bean = new PageBean(count,currentPage, pageobj);
		return bean;
	}
//	public List<PurchaseReturn> wq() throws Exception{
//		List<PurchaseReturn> d=ser.QueryBuy();
//		return d;
//	}
	
	//主祥新增
	@RequestMapping("/insertPurchaseReturn")
	@ResponseBody
	public String InsertPurchaseReturn(@RequestBody PurchaseReturn purchase) throws Exception{
		ser.InsertPurchaseReturn(purchase);
		return "新增成功！！！";
	}
	
	//查询最大单号   by 单据日期
	@RequestMapping("/queryBillNo")
	@ResponseBody
	public String QueryBillNo(@Param("date")String date) throws Exception{
		String num =ser.QueryBillNo(date);
		return num;
	}
	
	//查询 审核状态
	@RequestMapping("/querySatus")
	@ResponseBody
	public String QueryStatus(@Param("billNo")String billNo){
		return ser.QueryStatus(billNo);
	}
	
	@Autowired
	private SupplierService supser;
	
	//查询供应商
	@RequestMapping("/querySupplier")
	@ResponseBody
	public List<Supplier> QuerySupplier(){
		List<Supplier> list = supser.QuerySupplier();
		return list;
	}
	
	//
	//新增
	@RequestMapping("/insertSupplier")
	@ResponseBody
	public void InsertSupplier(@RequestBody Supplier sup){
		supser.InsertSupplier(sup);
	}
	
	//分页查询
	@RequestMapping("/querySupplierPage")
	@ResponseBody
//	public List<Supplier> QuerySupplierPage(@Param("currentPage")int currentPage){
//		return supser.QuerySupplierPage(currentPage);
//	}
	public PageBean QuerySupplierPage(int currentPage) throws Exception{
		Integer count = this.supser.QuerySumCount();
		Object pageobj = this.supser.QuerySupplierPage(currentPage);
		PageBean bean = new PageBean(count,currentPage, pageobj);
		return bean;
	}
	
	@RequestMapping("/queryID")
	@ResponseBody
	public String QueryID(){
		return supser.QueryID();
	}
	
	@RequestMapping("/queryType")
	@ResponseBody
	public List<SupplierType> QueryType(){
		return supser.QueryType();
	}
	
	@RequestMapping("/updateSupplier")
	@ResponseBody
	public void UpdateSupplier(@Param("money")Double money,@Param("id")String id){
		ser.UpdateSupplier(money, id);
	}
	
	@RequestMapping("/updateProduct")
	@ResponseBody
	public void UpdateProduct(@Param("num")int num,@Param("money")Double money,@Param("id")String id){
		ser.UpdateProduct(num, money, id);
	}
	
}
